/*
 *  Copyright 2020-2025 the original author or authors.
 *  You cannot use this file unless authorized by the author.
 */

package org.ipig.constants;

import org.apache.commons.lang3.StringUtils;
import org.ipig.commons.conf.ehcache.EhcacheConf;
import org.ipig.commons.conf.http.HttpConf;
import org.ipig.commons.conf.kafka.consumer.KafkaConsumerConf;
import org.ipig.commons.conf.kafka.producer.KafkaProducerConf;
import org.ipig.commons.conf.mongo.MongoConf;
import org.ipig.commons.conf.redis.RedisConf;
import org.ipig.commons.conf.spike.SpikeConf;

/**
 * ConnectorCnst
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id$$
 * @since 1.0
 */
public class ConnectorCnst {
    public static final String CONN_JSON = "connJson";
    public static final String CONN_TYPE = "connType";
    public static final String CONN_CLASS = "connClass";

    /**
     * 连接器类型
     */
    public enum ConnType {
        /**
         * socket连接器
         */
//        SOCKET("socket", "socket连接器", SocketConf.class.getCanonicalName()),
        /**
         * http连接器
         */
        HTTP("http", "http连接器", HttpConf.class.getCanonicalName()),
        /**
         * local连接器
         */
        LOCAL("local", "local连接器", ""),
        /**
         * ehcache连接器
         */
        EHCACHE("ehcache", "ehcache连接器", EhcacheConf.class.getCanonicalName()),
        /**
         * redis连接器
         */
        REDIS("redis", "redis连接器", RedisConf.class.getCanonicalName()),
        /**
         * spike连接器
         */
        SPIKE("spike", "spike连接器", SpikeConf.class.getCanonicalName()),
        //rocketmq生产者连接器
//        ROCKETMQ_PRODUCER("rocketmq_producer", "rocketmq生产者连接器", RocketProducerConf.class.getCanonicalName()),
        //rocketmq消费者连接器
//        ROCKETMQ_CONSUMER("rocketmq_consumer", "rocketmq消费者连接器", RocketConsumerConf.class.getCanonicalName()),
        //elasticsearch连接器
//        ELASTICSEARCH("elasticsearch", "elasticsearch连接器","cn.gov.zjport.skeleton.search.conf.ClientManagerConf"),
        //kafka生产者连接器
        KAFKA_PRODUCER("kafka_producer", "kafka生产者连接器", KafkaProducerConf.class.getCanonicalName()),
        //kafka消息者连接器
        KAFKA_CONSUMER("kafka_consumer", "kafka消息者连接器", KafkaConsumerConf.class.getCanonicalName()),
        /**
         * mongodb连接器
         */
        MONGODB("mongodb", "mongodb连接器", MongoConf.class.getCanonicalName());
        /**
         * code
         */
        public final String code;
        /**
         * title
         */
        public final String title;
        /**
         * 默认配置类
         */
        public final String conf;

        /**
         * @param code  String
         * @param title String
         */
        ConnType(String code, String title, String conf) {
            this.code = code;
            this.title = title;
            this.conf = conf;
        }

        /**
         * parse
         *
         * @param code String
         * @return ConnType
         */
        public static ConnType parse(String code) {
            for (ConnType type : ConnType.values()) {
                if (StringUtils.equalsIgnoreCase(code, type.code)) {
                    return type;
                }
            }
            return null;
        }
    }
}